define(function (require, exports, module){
	var Form = require("form");
	var store =require("store");
	
	var instance = {
		initComponent: function (widget){
			var form=new Form({
				parentNode:".J-form",
				saveaction:function(){
					var data = form.getData();
					data.organization = store.get("user").organization.pkOrganization;
					data.creator = store.get("user").pkUser;
					widget.service.save(data,function(){
						widget.get("grid").refresh();
						widget.toList();
					});
				},
				cancelaction:function(){
					widget.toList();
				},
				model:{
					id:"form",
					layout:"2_1",
					items:[{
						name:"pkProductType",
						type:"hidden"
					},{
						name:"version",
						type:"hidden",
						defaultValue:"0"
					},{
						name: "seal",
						type: "hidden",
						defaultValue: "false"
					},{
						name:"name",
						label:"类型名称",
						validate:["required"]
					},{
						name:"product",
						label:"产品名称",
						type:"select",
						url:"api/product/query",
						keyField: "pkProduct",
						valueField: "name",
						validate:["required"]
					},{
						name:"creatorName",
						label:"创建人",
						defaultValue: store.get("user").name,
						readonly: true
					},{
						name:"createDate",
						type:"date",
						label:"创建时间",
						defaultValue: moment().format("YYYY-MM-DD"),
						readonly: true
					},{
						name:"description",
						label:"备注",
						type:"textarea",
						"break": true,
						exValidate: function(value){
							if(value.length>256){
								return "备注不能超过256个字";
							}else{
								return true;
							}
						}
					}]
				}
			});
			widget.set("form", form);
		}
	};
	module.exports = instance;
});